package org.example.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @SentinelResource(value = "addUser", blockHandler = "handleException")
    @RequestMapping(value = "/addUser", method = RequestMethod.GET)
    public String addUser() {
        return "User added successfully";
    }

    //限流处理类
    public String handleException(@NonNull BlockException ex) {
        return "系统繁忙，请稍后再试 ";
    }
}
